﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using mamnontuoitho7.AppCode;
using System.Data;

namespace mamnontuoitho7.module
{
    public partial class ProfileInfo : System.Web.UI.Page
    {
        private Member _member = new Member();
        protected DataRow _dtrMember;

        private string _memberID;


        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Check Permission
                _memberID = Session["memberID"].ToString();
                if (_memberID != "")
                {
                    if (!IsPostBack)
                    {
                        try
                        {
                            if (Request.QueryString["MemberID"] != null && Request.QueryString["MemberID"].ToString() != "")
                            {
                                loadMemberInformation(Request.QueryString["MemberID"].ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.Write(ex.Message);
                            Response.Write("<br/><br/><br/><h2>Có lỗi hệ thống hay lỗi mạng.</h2><br/><br/><br/>");
                        }
                    }
                }
                else
                {
                    Response.Write("<br/><br/><br/><h2>Bạn phải đăng nhập mới có thể truy cập thông tin thành viên.</h2><br/><br/><br/>");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Response.Redirect(ConstantClass._errorLoginPage);
            }
        }


        private void loadMemberInformation(String memberID)
        {
            _dtrMember = _member.GetMemberDetails(memberID);
            lblFullName.Text = _dtrMember["FullName"].ToString();
            lblBirthday.Text = _dtrMember["Birthday"].ToString();
            lblEmail.Text = _dtrMember["Email"].ToString();
            lblSex.Text = _dtrMember["Sex"].ToString() == "0" ? "Nữ" : "Nam";
            lblCareer.Text = _dtrMember["Career"].ToString();
            imgMember.ImageUrl = "../images/avatar/teacher_parents/" + (_dtrMember["Avatar"].ToString() == "" ? ConstantClass._memberDefaultAvatar : _dtrMember["Avatar"].ToString()) + "?" + DateTime.Now.Ticks;
        }

    }
}